Ext.define('Era.view.FinishScreen',{
    extend: 'Ext.container.Container',
    alias: 'widget.finishscreen',
    layout: 'hbox',
    
    items: [
        {
            xtype: 'button',
            text: 'Finish Event',
            tooltip: 'Display a list of options to finish this event.',
            handler: function() {
                //get record
                var record = this.findParentByType('finishscreen').record;
                
                // add record to history
                Era.controller.Main.getStore('history').add(record);
                
                // delete the record from the active events
                Era.controller.Main.getStore('events').remove(record);
            }
        },        
        {
            xtype: 'button',
            text: 'Edit Event',
            tooltip: 'Reschedule or change this event entirely.',
            handler: function() {
                
                //get record
                var record = this.findParentByType('finishscreen').record;
                
                // create edit form
                var screen = Ext.create('Era.view.EventScreen',{
                    buttons: [
                        {
                            text: 'Submit',
                            handler: function() {

                                // update the record
                                this.findParentByType('eventscreen').getForm().updateRecord(record);

                                // add to database
                                Era.controller.Main.getStore().update(record);

                                // create a grid with all events
                                var screen = Ext.create('Era.view.ManageScreen',{store: Era.controller.Main.getStore('events')});

                                // load grid in the menu panel
                                Era.controller.Main.showMenuScreen(screen);

                            }
                        },
                        {
                            text: 'Cancel',
                            handler: function() {

                                // create a grid with all events
                                var screen = Ext.create('Era.view.ManageScreen',{store: Era.controller.Main.getStore('events')});

                                // load grid in the menu panel
                                Era.controller.Main.showMenuScreen(screen);
                            }
                        }
                    ]
                });
                
                // load record in the form 
                screen.loadRecord(record);
                
                // load form in the menu panel
                Era.controller.Main.showMenuScreen(screen);
            }
        },
        {
            xtype: 'button',
            text: 'Delete Event',
            tooltip: 'Delete this event, all related data will be lost.',
            handler: function() {
                
                // get record
                var record = this.findParentByType('finishscreen').record;
                
                // delete the record from the database
                Era.controller.Main.getStore('events').remove(record);
                
                // create a grid with all events
                var screen = Ext.create('Era.view.ManageScreen',{store: Era.controller.Main.getStore('events')});

                // load grid in the menu panel
                Era.controller.Main.showMenuScreen(screen);
            }
        },
        {
            xtype: 'button',
            text: 'Cancel',
            tooltip: 'Return to previous menu.',
            handler: function() {
                
                // create a grid with all events
                var screen = Ext.create('Era.view.ManageScreen',{store: Era.controller.Main.getStore('events')});

                // load grid in the menu panel
                Era.controller.Main.showMenuScreen(screen);
            }
        },
    ]
});